$(function(){
	var headImage = localStorage.getItem("head_image"); 
	var ary = new Array();
	var $modal = $('#my-modal-loading');
	var page = 1;
	var query_id = localStorage.getItem("query_id");
	var person_role = localStorage.getItem("query_role");
	console.log("store_id:" + query_id);
	console.log("person_role:" + person_role);
	
	var urlPath = "http://yx.fxtourong.com/V1/Circle/circleMemberList" + "?store_id=" + query_id;
	
	var urlPath2 = "http://yx.fxtourong.com/V1/Circle/setManager" + "?store_id=" + query_id;
	var btn = $("#bottom_more");
	$modal.modal();
	getData();
	
	btn.click(function(){
		$modal.modal();
		page = page + 1;
		getData();
	});
		
	function getData(){
		$.ajax({
			type: "POST",
			url: urlPath,
			data: {
				token : localStorage.getItem("token"),
				page : page
			},
			dataType: "json",
			success: function(data) {
				$modal.modal('close');
				var code = data.code;
				console.log(code);
				if(code == "1") {
					btn.css("display", "block");
					var jsonStr = data.data;
					for(var i = 0; i<jsonStr.length; i++){
							var industry = jsonStr[i];
							ary.push(industry);
							var juse = industry.type;
							var juseType = "圈主";
							var setname = "设为管理员";
							if(juse == "1"){
								juseType = "普通圈友";
								setname = "设为管理员";
							} else if(juse == "2"){
								juseType = "管理员";
								setname = "设为普通圈友";
							} else if(juse == "3"){
								juseType = "圈主";
							}
							console.log(industry.identity);
							var imagehead = industry.avatar;
							if(headImage == imagehead){//圈主
								$("#member_ul").append("<li style='height:1px;'><div style='height:1px;border-bottom:1px solid #f5f6f7'></div></li><li value='" + (((page-1) * 10) + i) + "' class='am-g am-list-item-desced am-list-item-thumbed am-list-item-thumb-left' onclick=''>" + 
						        "<div class='am-u-sm-2 am-list-thumb'>" +
						         "<img class='am-circle' src='" + industry.avatar + "' style='width: 48px;height: 48px;margin-left: 10px;'/>" + 
						        "</div>" + 
						        "<div class=' am-u-sm-3 am-list-main' style='margin-top: 0px;'>" + 
						            "<p class='am-list-item-text'><span style='font-size: 16px;margin-left: 8px;font-size:14px;color: #333;'>" + industry.nickname + "</span></p>" + 
						            "<p class='am-list-item-text'><span style='font-size: 16px;margin-left: 8px;font-size:12px;color: #BBB;'>" + juseType + "</span></p>" + 
						        "</div>" + 
						        "<div class=' am-u-sm-7 am-list-main' style='margin-top: 10px;'>" + 
						        	"<button value='" + (i + 10*(page - 1)) + "' class='am-btn am-btn-secondary am-round set_person' style='font-size: 12px;float: right;margin-right: 10px;display:none;'>" + "个人信息" + "</button>" +
						        	"<button value='" + (i + 10*(page - 1)) + "' class='am-btn am-btn-secondary am-round' style='font-size: 12px;float: right;margin-right: 10px;display:none;'>" + setname + "</button>" +
						        "</div>" +
					      	"</li>");
							} else {
								$("#member_ul").append("<li style='height:1px;'><div style='height:1px;border-bottom:1px solid #f5f6f7'></div></li><li value='" + (((page-1) * 10) + i) + "' class='am-g am-list-item-desced am-list-item-thumbed am-list-item-thumb-left'>" + 
						        "<div class='am-u-sm-2 am-list-thumb'>" +
						         "<img class='am-circle' src='" + industry.avatar + "' style='width: 48px;height: 48px;margin-left: 10px;'/>" + 
						        "</div>" + 
						        "<div class=' am-u-sm-3 am-list-main' style='margin-top: 0px;'>" + 
						            "<p class='am-list-item-text'><span style='font-size: 16px;margin-left: 8px;font-size:14px;color: #333;'>" + industry.nickname + "</span></p>" + 
						            "<p class='am-list-item-text'><span style='font-size: 16px;margin-left: 8px;font-size:12px;color: #BBB;'>" + juseType + "</span></p>" + 
						        "</div>" + 
						        "<div class=' am-u-sm-7 am-list-main' style='margin-top: 10px;'>" + 
						        	"<button value='" + (i + 10*(page - 1)) + "' class='am-btn am-btn-secondary set_person' style='font-size: 13px;float: right;margin-right: 15px;display:inline;border-radius: 3px;padding: 7px 10px;' onclick=''>" + "设置" + "</button>" +
						            "<button value='" + (i + 10*(page - 1)) + "' class='am-btn am-btn-secondary set_juese' style='font-size: 13px;float: right;margin-right: 15px;display:inline;border-radius: 3px;padding: 7px 10px;'>" + setname + "</button>" +
						        "</div>" +
					      	"</li>");
							}
						}
					if(person_role == "3"){
						$(".set_juese").css("display", "inline");
					} else {
						$(".set_juese").css("display", "none");
					}
				} else {
					btn.css("display", "none");
				}
			},
			error: function(e){
				$modal.modal('close');
			}
		});
	}
	
	$(document).on("click",".set_person",function(){
			var m = $(this).val();
			$(this).addClass('shit');
			localStorage.setItem("person_id", ary[m].uid);
			console.log(ary[m].uid);
			location.href = "person_main.html";
	});
	
	$(document).on("click",".set_juese",function(){
			var m2 = $(this).val();
			var m = $(this).text();
			console.log("chengyuanid:" + ary[m2].uid);
			if(m == "设为管理员"){
				$.ajax({
					type: "POST",
					url: urlPath2,
					data: {
						token : localStorage.getItem("token"),
						uid: ary[m2].uid,
						type: 2
					},
					dataType: "json",
					success: function(data) {
						console.log(data);
						var code = data.code;
						console.log(code);
						if(code == "1") {
							new Toast({context:$('body'),message:'设置成功'}).show();
						} else {
							new Toast({context:$('body'),message:'设置失败'}).show();
						}
					}
				});
			} else {
				$.ajax({
					type: "POST",
					url: urlPath2,
					data: {
						token : localStorage.getItem("token"),
						uid: ary[m2].uid,
						type: 1
					},
					dataType: "json",
					success: function(data) {
						console.log(data);
						var code = data.code;
						console.log(code);
						if(code == "1") {
							new Toast({context:$('body'),message:'设置成功'}).show();
						} else {
							new Toast({context:$('body'),message:'设置失败'}).show();
						}
					}
				});
			}
		return false;	
	});
	$("#approve").click(function(){
		if(person_role == "3" || person_role == "2" ){
		location.href = "query_shenpi.html";;
	} else {
		alert("普通圈友无权限进行该操作");
	}
	});	
	$("#blacklist").click(function(){
		if(person_role == "3" || person_role == "2" ){
		location.href = "query_hei.html";;
	} else {
		alert("普通圈友无权限进行该操作");
	}
	});	
}); 
